<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue</title>
  <script src="../js/vue.js"></script>
</head>
<body>
  <div id="app">
    {{msg}}
    <!-- 3.组件的使用 -->
    <br>
    <my-component></my-component>
    <my-component2></my-component2>
    <!-- <br>
    <my-component></my-component> -->
  </div>
  <script>
    // 1.声明组件
    let myComponent2 = {
      data() {
        return {
          age: 12
        }
      },
      template: `
        <button @click="clickHandler">子组件2{{age}}</button>
      `,
      methods: {
        clickHandler() {
          this.age = 20
        }
      }
    }
    let myComponent = {
      data() {
        return {
          name: '张三'
        }
      },
      template: `
        <button @click="clickHandler">
          子组件按钮{{name}}
          
        </button>
      `,
      methods: {
        clickHandler() {
          this.name = "李四"
        }
      },
      components: {
        'my-component2': myComponent2
      }
    }
    
    // 2.组件注册（全局注册）
    // Vue.component('my-component',myComponent)
    
    let vm = new Vue({
      el: '#app',
      data: {
        msg: 'hello vue'
      },
      methods: {
        
      },
      components: {
        'my-component': myComponent
      }
    })
  </script>
</body>
</html>